GBML manual / Backgrounds

Tile layers - Front, Main and Back

A room can paint tiles on three layers - Main (the room's own, the only one with collision), Front (over the player, like treetops) and Back (behind everything, like far hills) - each with its own scroll speed and effect.

Three layers of tiles

A room's tiles are normally one layer: the floor, the walls and everything else you paint with the Room Editor's Tile Palette. That is the Main layer, and it is the only one that blocks things. A room can also have two more layers of tiles:

LayerDrawnGood for
Frontin front of the Main layertreetops and roofs, fog, a cave's dark edge
Mainthe room's own tilesthe floor, the walls, everything that has collision and tile flags
Backbehind the Main layerfar hills, far clouds, a cave wall behind the floor

The extra layers are painted with the same tile set as the Main layer, so they need no new tiles and no new colors: a Front layer of treetops costs nothing but the one background layer it is drawn on.

Adding a layer and painting on it

  1. In the Tile Palette, open Tile layers and press + Add tile layer. If both places are free it asks Back or Front; if one is taken it adds the other. The new layer is empty and is picked right away.
  2. Painting on (Front / Main / Back) says which layer every paint tool paints on: the pencil, the brushes, the rectangle, the fill, the autotiles, Draw slope and Draw Curve all work on the picked layer exactly as they do on Main. You can also pick a layer by clicking its name in Layers.
  3. The Attribute brush (collision and tile flags) belongs to Main. With Front or Back picked it paints nothing and says so; pick Main to paint collision.
  4. Remove the Front layer (or Back) takes the layer out of the room with the tiles painted on it. Undo brings it back.

The Map and the other thumbnails of the room draw every layer.

Scroll speed

Each Front or Back layer has its own Scroll speed, across and down, in percent: 100 moves with the room (the default), 50 moves half as far as the camera so the layer looks far away, 0 stays where it is on the screen, and a minus number moves the other way. The layer moves in whole pixels, so it never shakes. A Back layer at 30 or 50 is how you make far hills, and a Front layer at 120 makes a bush that rushes past. room_layer_scroll_speed changes it from code.

Effect

Every layer, Main too, has an Effect dropdown. It plays on that one layer while the others stay still, and the Room Editor's canvas plays it live:

The same looks are available from code with room_layer_look (Wobble), screen_mosaic (Blocks) and screen_blend (Fade), each with a layer.

Drawing order, the eye and the half-moon

In Layers, every layer is a row you can drag by its grip, among the room's pictures and depth groups: a layer dragged in front of a depth group puts that group's objects behind it. This is how a Front layer of treetops ends up over the player: put the player in a depth group and drag the Front layer in front of that group. (A game with no depth groups draws all its objects in front of every layer.) A room has three drawing levels, so a layer is refused (with the reason) when the order would need a fourth. The eye hides a row and the half-moon button makes it see-through; both are for the editor only, so you can paint on Main while Back is faded. They are not part of the game.

Animated tiles and color cycles

Tile animations (see tile animation) and an autotile's color cycle belong to the tile set, so they play on every layer: a lantern drawn with an animated tile moves on a Front layer, and glowing cracks painted only on a Back layer still cycle their colors.

What a layer costs

Collision layers change only Main

Collision layers (the numbered versions of a room you switch with tile_layer_set_active) change the Main layer: its collision and the pictures of its squares. A Front or Back layer looks the same in every collision layer, because it is not part of what a collision layer changes. When you paint on a Front or Back layer while a collision layer other than layer 1 is on screen, the Tile layers section reminds you of that. If a door has to look open, draw its open look on Main, or hide a layer with room_layer_visible when the door opens.

In code

CallWhat it does
room_layer_scroll_speedchanges a layer's scroll speed
room_layer_visibleshows or hides a layer
room_layer_lookstarts or ends a wobble on a layer
tile_index and tile_set_indexread and change the picture of a layer's square, with the layer as the last argument

A layer is named with ROOM_LAYER_MAIN, ROOM_LAYER_FRONT or ROOM_LAYER_BACK. A room that does not have the layer you name does nothing. A game that never adds a layer carries none of this.

On other consoles

A console that cannot draw a room's tiles on separate layers grays out the Tile layers section, and the room is drawn without them.

See also: BackgroundsCollision layersroom_layer_scroll_speedroom_layer_visibleroom_layer_lookROOM_LAYER_MAINROOM_LAYER_FRONTROOM_LAYER_BACKtile_indextile_set_indexTile animationAutotilebackground_scroll_speedOne picture, several palettes